#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

void* thread1(void* arg)
{
    int i = *(int*)arg;
    printf("线程1循环次数为%d次\n",i);
    while((i) > 0)
    {
        printf("线程1被运行\n");
        i--;
        sleep(2);
    }
    return "线程1结束";  
}

void* thread2(void* arg)
{
    int i = *(int*)arg;
    printf("线程2循环次数为%d次\n",i);
    while ((i) > 0)
    {
        printf("线程2被运行\n");
        (i)--;
        sleep(1);
    }
    return "线程2结束";    
}

int main(int argc, char const *argv[])
{
    pthread_t pid_1;
    pthread_t pid_2;

    int a = 5;
    int b = 3;
    pthread_create(&pid_1,NULL,thread1,&a);
    pthread_create(&pid_2,NULL,thread2,&b);

    void* re1;
    void* re2;

    pthread_join(pid_1,&re1);
    pthread_join(pid_2,&re2);

    printf("%s\n",(char*)re1);
    printf("%s\n",(char*)re2);


    //....

    return 0;
}
